<?php
namespace App\Modules\Relationship\Models;


use App\Http\Services\CommonServices;
use App\Modules\Relationship\Interfaces\ModelInterface;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class TaskUpperLimitModel extends Base {

    protected $table = "rs_task_upper_limit";
    protected $fields = ['id', 'rs_code as rsCode', 'task_id as taskId', 'upper_limit as upperLimit'];
    protected $tablePrefix = '';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
        $this->tablePrefix = env('DB_PREFIX');
    }

    // 查记录
    public function getRecordByRscode ($rscode, $taskId){
        $condition = array(
            "rs_code"=>$rscode,
            "task_id"=>$taskId,
            "is_deleted"=>0
        );
        $return = $this->getOneByCondition($condition, $this->fields);
        return $return;
    }

    public function insertUpperLimit ($rsCode, $taskId, $upperLimit = 0) {
       return DB::table($this->table)->insert([
            'rs_code'=>$rsCode,
            'task_id'=>$taskId,
            'upper_limit'=>$upperLimit
            ]);
    }

    public function updateUpperLimit ($id, $upperLimit = 0) {
        return DB::table($this->table)->where('id', $id)->update([
            'upper_limit'=>$upperLimit
        ]);
    }

    public function deleteUpperLimit ($rsCode) {
        return DB::table($this->table)->where('rs_code', $rsCode)->update([
            'is_deleted'=>1
        ]);
    }
}

